package cn.kgc.springboot.util;

import java.util.Random;

/**
 * @author: hengge
 * @version: v1.0
 * @DATE: 2022/12/1
 * 随机盐工具类
 */
public class SaltUtil {

    public static String getSalt(int length){  //设置需要随机盐的个数
        //将一组字符串传入chars数组中
        char[] chars = "qwertyuiopSDSFDBDHlkjhgfdsazxcvbnm,.;[]'!@#%^*()_".toCharArray();
        //拼接字符串
        StringBuilder sb = new StringBuilder();
        //获取几个字符
        for (int i = 0; i < length; i++) {
            Random random = new Random();
            //获取数组长度之间的字符
            int randomNumber = random.nextInt(chars.length);
            //随机获取的字符进行拼接
            sb.append(chars[randomNumber]);
        }

        return sb.toString();  //返回一个String类型的数据
    }
}
